/*
 * @Author: your name
 * @Date: 2024-05-14 10:47:41
 * @LastEditTime: 2024-05-14 10:53:39
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\46.全排列.cpp
 */
/*
 * @lc app=leetcode.cn id=46 lang=cpp
 *
 * [46] 全排列
 */

// @lc code=start
class Solution {
public:
    vector<int> path;
    vector<vector<int>> res;
    void backtracking(vector<int>& nums, vector<int>& used){
        if(path.size() == nums.size()){
            res.push_back(path);
            return;
        }
        // 遍历num数组找到还没使用的元素
        for(int i = 0; i < nums.size(); i++){
            if(used[i] == 1){
                continue;
            }
            used[i] = 1;
            path.push_back(nums[i]);
            backtracking(nums, used);
            path.pop_back();
            used[i] = 0;
        }
    }
    vector<vector<int>> permute(vector<int>& nums) {
        vector<int>used(nums.size(), false);
        backtracking(nums, used);
        return res;
    }
};
// @lc code=end

